package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.SystemNotice;
import cn.wolfcode.trip.base.domain.User;
import cn.wolfcode.trip.base.mapper.SystemNoticeMapper;
import cn.wolfcode.trip.base.mapper.UserMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.ISystemNoticeService;
import cn.wolfcode.trip.base.service.IUserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 系统公告(消息)服务接口的实现
 */
@Service
public class SystemNoticeServiceImpl implements ISystemNoticeService {

    @Autowired
    private SystemNoticeMapper systemNoticeMapper;
    @Autowired
    private UserMapper userMapper;

    //增加
    @Override
    public void saveAll(SystemNotice entity) {
        List<Long> ids = userMapper.selectAll();
        int size = ids.size();
        for (Long id : ids) {
            entity.setUserId(id);
            systemNoticeMapper.insertAll(entity);
        }
    }

    //获取内容
    @Override
    public List<SystemNotice> selectSystemNotice(Long userId) {
        List<SystemNotice> systemNotices = systemNoticeMapper.selectSystemNotice(userId);
        int size = systemNotices.size();
        if (size>0){
            Long[] array = new Long[size];
            for(int i=0;i<size;i++){
                array[i] = systemNotices.get(i).getId();
            }
            systemNoticeMapper.updateNoticeState(array);
        }
        return systemNotices;
    }

    //消息数
    @Override
    public Integer selectNoticeNumber(Long userId) {
        return systemNoticeMapper.selectNoticeNumber(userId);
    }
}
